package com.example.win.android_banduyujia.peopleactivity.activity.activity.payactivtiy;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Spinner;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.adapter.AccoutAdapter;
import com.example.win.android_banduyujia.database.Paydatabase;
import com.example.win.android_banduyujia.entity.PayEntity;
import com.example.win.android_banduyujia.peopleactivity.ui.layout.RefreshLayout;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by Win on 2015/9/2.
 */
public class AccoutBalanceActivity extends Activity implements SwipeRefreshLayout.OnRefreshListener,
        RefreshLayout.OnLoadListener, AdapterView.OnItemClickListener, View.OnClickListener {
    public static final String TAG = AccoutBalanceActivity.class.getSimpleName();

    private RefreshLayout  swipeLayout;
    private ListView   mListView;
    private AccoutAdapter adapter;
    private ArrayList<HashMap<String, String>>  list;
    private View header;

    public List<PayEntity>  mPayList;
    public Paydatabase      mDataBase;

    public ArrayAdapter<String>   madapter;
    public Spinner spinner;
    public ImageView  mImageBack;
    public int resData;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_accout_balance_page);

        InitTitles();
        InitViews();
        setData();
        setListener();
    }

    private void InitTitles() {
        mImageBack = (ImageView) findViewById(R.id.title_spinner_back);
        mImageBack.setOnClickListener(this);

        spinner=(Spinner)findViewById(R.id.title_spinner_text);

        madapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, getDataSource());
        spinner.setAdapter(madapter);
    }

    public List<String> getDataSource() {
        List<String>  lists = new ArrayList<String>();

        lists.add("全部");
        lists.add("收入");
        lists.add("支出");

        return lists;
    }

    private void InitViews() {
        header = getLayoutInflater().inflate(R.layout.layout_refresh_header, null);
        swipeLayout=(RefreshLayout)findViewById(R.id.layout_list_accout_balance);
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setColorScheme(android.R.color.holo_blue_light,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
    }

    private void setData() {
        list = new ArrayList<HashMap<String, String>>();
        list.add(new HashMap<String, String>());
        String[]  dabaset = new String[100];
        for(int i = 0; i <dabaset.length ; i++){
            list.add(new HashMap<String, String>());
        }
        mListView = (ListView)findViewById(R.id.layout_list_view_all);
        mListView.addHeaderView(header);
        mListView.setOnItemClickListener(this);

        adapter = new AccoutAdapter(this, list);
        mListView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }

    private void setListener() {
        swipeLayout.setOnRefreshListener(this);
        swipeLayout.setOnLoadListener(this);
    }

    @Override
    public void onRefresh() {
        swipeLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
                swipeLayout.setRefreshing(false);
            }
        }, 1000);
    }

    @Override
    public void onLoad() {
        swipeLayout.postDelayed(new Runnable() {
            @Override
            public void run() {
               swipeLayout.setLoading(false);
            }
        }, 1000);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case  R.id.title_spinner_back:
                  AccoutBalanceActivity.this.finish();
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // String entity = mPayList.get(position-1).getBalance();


    }
}
